package com.eol.web.utils;

import com.eol.common.base.BaseResponseCode;
import com.eol.common.context.BaseContextHandler;
import com.eol.common.exception.BaseException;
import com.eol.common.jwt.TokenData;
import com.eol.entity.po.member.ZMember;
import com.eol.service.member.ZMemberService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * AppCommonUtils
 *
 * @author liulinhui
 * @email 1249055292@qq.com
 * @date 2020/6/1 22:56
 */
@Component
public class AppCommonUtils {

    @Resource
    private ZMemberService zMemberService;

    public ZMember getMemberInfo() {
        TokenData tokenData = BaseContextHandler.getTokenData();
        if (null == tokenData) throw new BaseException(BaseResponseCode.TOKEN_INVALID);
        return zMemberService.selectOne(ZMember.builder().id(tokenData.getUserId()).build());
    }

    public boolean ifLogin() {
        return null != BaseContextHandler.getTokenData();
    }
}
